module system
   (
    input signed [6:0] lat_inic, lat_final, long_inic, long_final,
    output [6:0]       ones_bcd, tens_bcd 
    );
   
   wire [6:0] 	       resta_lat, resta_long;
   wire [6:0] 	       vabs_lat, vabs_long;
   wire [6:0] 	       val_min, val_max;
   wire [6:0] 	       min_shifted_val, max_shifted_val;
   wire [6:0] 	       resta_max_shift_3b;
   wire [6:0] 	       sum_de_shifted_vals;
   wire [6:0] 	       mini_final, maxi_final;
   wire [3:0] 	       tmp_ones_bcd , tmp_tens_bcd;

   resta restador_lat (
		       .a(lat_inic), 
		       .b(lat_final), 
		       .out(resta_lat)
		       );
   
   
   resta restador_long (
			.a(long_inic), 
			.b(long_final), 
			.out(resta_long)
			);
   
   
   vabsoluto vabsoluto_lat (
			    .invab(resta_lat), 
			    .outvab(vabs_lat)
			    );
   
   
   vabsoluto vabsoluto_long (
			     .invab(resta_long), 
			     .outvab(vabs_long)
			     );

   
   compminmax comp_lat_long (
			     .a(vabs_lat), 
			     .b(vabs_long), 
			     .mini(val_min), .maxi(val_max)
			     );

   
   shift_right_1b shift_1b (
			    .a(val_min), 
			    .shifted_number(min_shifted_val)
			    );

   
   shift_right_3b shift_3b (
			    .a(val_max), 
			    .shifted_number(max_shifted_val)
			    );

   
   resta restador_shift_3b_vals (
			    .a(val_max), 
			    .b(max_shifted_val), 
			    .out(resta_max_shift_3b)
			    );
   

   sum sum_shift_1b_resta_s_3b (
				.a(min_shifted_val), 
				.b(resta_max_shift_3b), 
				.out(sum_de_shifted_vals)
				);

   
   compminmax val_final (
			 .a(sum_de_shifted_vals), 
			 .b(val_max), 
			 .mini(mini_final), 
			 .maxi(maxi_final)
			 );

   bin2bcd b2bcd (
		  .bin(maxi_final),
		  .ones(tmp_ones_bcd),
		  .tens(tmp_tens_bcd)
		  );
   
   assign ones_bcd = tmp_ones_bcd;
   assign tens_bcd = tmp_tens_bcd;
   
endmodule // system
